﻿package com.kt.common.result;

import lombok.Data;

/**
 * @author kt
 * @since 2024/3/10
 */
@Data
public class Result {
    private int code;
    private String message;
    private Object data;

    private Result() {

    }

    public static Result build(Object data, int code, String message) {
        Result result = new Result();
        result.setCode(code);
        result.setMessage(message);
        if (data != null) {
            result.setData(data);
        }
        return result;
    }

    public static Result build(Object data, ResultCode resultCode) {
        return build(data, resultCode.getCode(), resultCode.getMessage());
    }

    public static Result success() {
        return success(null);
    }

    public static Result success(Object data) {
        return build(data, ResultCode.SUCCESS);
    }

    public static Result fail() {
        return fail(null);
    }

    public static Result fail(Object data) {
        return build(data, ResultCode.FAIL);
    }
}
